package com.example.demo.mapper.log;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.bean.PageRes;
import com.example.demo.bean.log.SysLoginLogDO;
import com.example.demo.bean.log.SysOperLogDO;
import com.example.demo.convert.SysOperLogConvert;
import com.example.demo.dto.log.SysLoginLogPageReqVO;
import com.example.demo.dto.log.SysOperLogPageReqVO;
import com.example.demo.dto.log.SysOperLogRepVO;
import com.example.demo.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.stream.Collectors;

@Mapper
public interface SysOperLogMapper extends BaseMapperX<SysOperLogDO> {

    default PageRes<SysOperLogDO> selectPage(SysOperLogPageReqVO reqVO) {
        Page<SysOperLogDO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        return selectPageCommon(page, new QueryWrapper<SysOperLogDO>()
                .like(ObjectUtil.isNotNull(reqVO.getOperLocation()), "oper_location", reqVO.getOperLocation())
                .like(ObjectUtil.isNotNull(reqVO.getTitle()), "title", reqVO.getTitle())
                .like(ObjectUtil.isNotNull(reqVO.getOperName()), "oper_name", reqVO.getOperName())
                .eq(ObjectUtil.isNotNull(reqVO.getStatus()), "status", reqVO.getStatus())
                .eq(ObjectUtil.isNotNull(reqVO.getOperType()), "oper_type", reqVO.getOperType())
                .between(
                        ObjectUtil.isNotNull(reqVO.getTimeArr()),
                        "oper_time",
                        ArrayUtil.get(reqVO.getTimeArr(), 0),
                        ArrayUtil.get(reqVO.getTimeArr(), 1)
                )
        );
    }
}
